package com.arpa.wms.scheduled.task;

import com.arpa.wms.scheduled.domain.entity.OmsOrderSet;
import com.arpa.wms.scheduled.service.IOmsOrderSetService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 定时服务重启后自动启动定时任务
 * @author liuxr
 * @date 2021年08月16日 11:07
 */
@Component
@Order(value = 1)
@Log4j2
public class ScheduledTaskRunner implements ApplicationRunner {


    @Autowired
    private IOmsOrderSetService omsOrderSetService;

    /**
     * 程序启动完毕后,需要自启的任务
     */
    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        log.info(" >>>>>> 项目启动完毕, 开启 => 需要自启的任务 开始!");
        List<OmsOrderSet> scheduledTaskBeanList = omsOrderSetService.list(new LambdaQueryWrapper<OmsOrderSet>().eq(OmsOrderSet::getStatus,0));
        omsOrderSetService.initAllTask(scheduledTaskBeanList);
        log.info(" >>>>>> 项目启动完毕, 开启 => 需要自启的任务 结束！");
    }
}
